<?php
namespace app\web\controller;

use app\model\Theme; 
use app\model\Poster; 
use app\model\Order; 

class Themeimport extends Base
{
    public function Themeimport()
    {
global $_G, $_P;
$system = $_G['system'];
$serverconfigs = db_find("SELECT * FROM ".tablename('00serverconfig')." WHERE id =1 ");
$system['s']  = !empty($serverconfigs['settings']) ? xunserializer($serverconfigs['settings']) : array();   

$_G['page']['title'] = '活动导入 - ' . $system['sysname'];
//load_func('tpl');
$GLOBALS['frames'] = array();
$themeid = Theme::getDefaultThemenew();

$id = intval($_P['id']);
$do = 'themeimport';
$op = !empty($_P['op']) ? $_P['op'] : 'display';
if(!empty($themeid) && $op !== 'finished' && $op !== 'delete'){
	return_msg('当前软件里已添加活动，不可导入');
}
$url = createWebUrl($do,array('op' => 'display','themeid'=>$themeid));

$soft = $_P['soft'];
if (mb_strlen($soft)!=5 || !is_numeric($soft)) {
	return_msg('软件编号必须为5位数字');
}

$severurl = "http://cdn" . substr($soft, 0, 2) .".yixuanrj.cn/app/index.php?i=2&c=home&a=getdata&do=";
$shouxu = 1 - Order::shouxufei();

if ($op == 'first') {
	$info = Poster::softpandun($severurl ,$soft);
	$info = Poster::softfirst($severurl ,$soft);
	$list = $info['theme'];
	$count = $info['count'];
	$softname = $info['softname'];
	$total = count($list);
	$totaldaozhang = 0;
	foreach ($list as $index => $row) {
		$list[$index]['daozhang']=sprintf("%.2f",$row['ordercount']*$shouxu+$row['commcount']+$row['chongzhi']);
		$totaldaozhang = $totaldaozhang + $list[$index]['daozhang'];
	}
	$return_clicent = get_defined_vars();
return view('/themeimport' , $return_clicent);
}
if ($op == 'delete') {
	$softname = MODULE_NAME;
	$count['commshare'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_acommshare") );
	$count['share'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_ashare") );
	$count['relation'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_arelation") );
	$count['scan'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_ascan") );
	$count['fans'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_afans") );
	$count['order'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_aorder") );
	$count['comm'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_acomm") );
	$count['code'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_acode") );
	$count['exchange'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_aexchange") );
	$count['fake'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_afake") );
	$count['fanpaichoujiang'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_afanpaichoujiang") );
	$count['fanpaijihui'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_afanpaijihui") );
	$count['friend'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_afriend") );
	$count['hexiao'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_ahexiao") );
	$count['team'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_ateam") );
	$count['worker'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_aworker") );
	$count['workerreport'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_aworkerreport") );
	$count['theme'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_atheme") );
	$count['config'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_aconfig") );
	$count['gift'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_agift") );
	$count['giftgroup'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_agiftgroup") );
	$count['record'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_arecord") );
	$count['poster'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_aposter") );
	$count['qrlist'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_aqrlist") );
	$count['rea'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_area") );
	$count['shangjia'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_ashangjia") );
	$count['shangjiagroup'] = db_query ( "TRUNCATE TABLE " . tablename($softname."_ashangjiagroup") );
	$input =array();
	$this->saveSettings($input);

	$url = createWebUrl($do, array('op'=>'first','soft'=>$soft));
	return_msg("所有数据已清空",$url);
}
if ($op == 'finished') {
	$info = Poster::softfirst($severurl ,$soft);
	$list = $info['theme'];
	$countsource = $info['count'];
	$softname = $info['softname'];
	
	$softnamesource = $softname;
	$softname = MODULE_NAME;
	$count['record'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_arecord") );
	$count['order'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_aorder") );
	$count['fans'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_afans") );
	$count['commshare'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_acommshare") );
	$count['share'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_ashare") );
	$count['relation'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_arelation") );
	$count['scan'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_ascan") );
	$count['comm'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_acomm") );
	$count['code'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_acode") );
	$count['exchange'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_aexchange") );
	$count['fake'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_afake") );
	$count['fanpaichoujiang'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_afanpaichoujiang") );
	$count['fanpaijihui'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_afanpaijihui") );
	$count['friend'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_afriend") );
	$count['hexiao'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_ahexiao") );
	$count['team'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_ateam") );
	$count['worker'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_aworker") );
	$count['workerreport'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_aworkerreport") );
	$count1 = $count;
	$count ='';
	$count['theme'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_atheme") );
	$count['config'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_aconfig") );
	$count['gift'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_agift") );
	$count['giftgroup'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_agiftgroup") );
	$count['poster'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_aposter") );
	$count['qrlist'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_aqrlist") );
	$count['rea'] = db_fetchcolumn ( "SELECT COUNT(*) FROM " . tablename($softname."_area") );
	$count['shangjia'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_ashangjia") );
	$count['shangjiagroup'] = db_fetchcolumn ( "SELECT COUNT(id) FROM " . tablename($softname."_ashangjiagroup") );

	$count1key = array_keys($count1);
	$countkey  = array_keys($count);

	//输写日志
	$tips="";
	foreach ($countkey as $index => $item) {
		 $chayi = $countsource[$item]-$count[$item];
		 if ($chayi !== 0) {
		 	$tips .= $item .'	导入：'.$count[$item].'条，'. $chayi.'条未导入<br>';
		 }else{		 	
		 	$tips .= $item .'	导入：'.$count[$item].'条<br>';
		 }
	}
	if ($_P['copytype']=='all') {
		$tipstitle = '活动全部导入来自【'.$softnamesource.'】';

	    $list = Theme::getList('1=1',1,500);
	    $shuju='';
		foreach ($list as $index =>$row){
			$row['recordcount'] = intval(db_fetchcolumn ( 'SELECT COUNT(*) FROM ' . tablename ( t_record ) . "
					WHERE themeid = '{$row['id']}' and status > 0  and status!=3" ));
			$row['fanscount'] = intval(db_fetchcolumn ( 'SELECT COUNT(*) FROM ' . tablename ( t_fans ) . "
					WHERE themeid = '{$row['id']}' " ));
			$row['ordercount'] = floatval(db_fetchcolumn ( 'SELECT sum(realfee) FROM ' . tablename ( t_order ) . "
					WHERE themeid = '{$row['id']}' and paystate = 1 and realfee > 0 " ));
			$row['ordercount'] = sprintf("%.2f", $row['ordercount']);

			$row['commcount'] = floatval(db_fetchcolumn ( 'SELECT sum(fee) FROM ' . tablename ( t_comm ) . "
	            WHERE themeid ='{$row['id']}'  and status  = 1 " ));
			$row['commcount'] = -sprintf("%.2f", $row['commcount']);
			$shuju.='活动'.$row['id'].'参与人数：'.$row['fanscount'].'<br>';
			$shuju.='活动'.$row['id'].'浏 览 量：'.$row['scansum'].'<br>';
			$shuju.='活动'.$row['id'].'转 发 量：'.$row['forward'].'<br>';
			$shuju.='活动'.$row['id'].'付款人数：'.$row['recordcount'].'<br>';
			$shuju.='活动'.$row['id'].'付款金额：'.$row['ordercount'].'<br>';
			$shuju.='活动'.$row['id'].'红包发放：'.$row['commcount'].'<br>';
			if ($row['chongzhi']>0) {
				$shuju.='活动'.$row['id'].'充&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;值：&nbsp;'.$row['chongzhi'].'<br>';
			}else{
				$shuju.='活动'.$row['id'].'已  提  现：'.$row['chongzhi'].'<br>';
			}			
			$shuju.='活动'.$row['id'].'实际到帐：'.sprintf("%.2f",$row['ordercount']*$shouxu+$row['commcount']+$row['chongzhi']).'<br><br>';
		}
		foreach ($count1key as $index => $item) {
			 $chayi = $countsource[$item]-$count1[$item];
			 if ($chayi !== 0) {
			 	$tips .= $item .'	导入：'.$count1[$item].'条，'. $chayi.'条未导入<br>';
			 }else{		 	
			 	$tips .= $item .'	导入：'.$count1[$item].'条<br>';
			 }
		}
	}else{
		$tipstitle = '活动只导入活动【'.$softnamesource.'】';
	}
	// db_query ( "TRUNCATE TABLE " . tablename($softname."_alog") );
	$r = writelogcz($system,0,$tipstitle,$shuju.$tips,$_G['username']);
	$return_clicent = get_defined_vars();
return view('/themeimport' , $return_clicent);
}

if ($op == 'copytheme') {
	$info = Poster::softfirst($severurl ,$soft);
	$list = $info['theme'];
	$countsource = $info['count'];
	$softname = $info['softname'];

	//复制活动信息
	Poster::softcopytable($severurl,$uniacid,$softname,'gift','');
	Poster::softcopytable($severurl,$uniacid,$softname,'giftgroup','');
	// Poster::softcopytable($severurl,$uniacid,$softname,'log','');
	Poster::softcopytable($severurl,$uniacid,$softname,'poster','');
	Poster::softcopytable($severurl,$uniacid,$softname,'qrlist','');
	Poster::softcopytable($severurl,$uniacid,$softname,'rea','');
	Poster::softcopytable($severurl,$uniacid,$softname,'shangjia','');
	Poster::softcopytable($severurl,$uniacid,$softname,'shangjiagroup','');
	
	Poster::softcopytable($severurl,$uniacid,$softname,'config','');
	
	$url=$_G['siteroot']."app/index.php?i=".$_G['mpid']."&c=entry&m=".MODULE_NAME;
	//http://gongzhuling.kissbaby.net.cn/app/00rewrite.php?c=entry&m=softname&i=2&themeid=1&fromuid=0&do=w_init&soft=knUBneD8I&wxref=mp.weixin.qq.com
	//http://gongzhuling.kissbaby.net.cn/app/index.php?i=2&c=entry&do=getqr&m=yx30999&op=get&server=31.yixuan.net&softname=kk31166&themeid=1&uniacid=2&softkey=AI2dQeeGd

	$info = Poster::softpost($severurl . 'themecopysetting' ,array('softname' => $softname,'newname' => MODULE_NAME,'url'=>$url,'copytype'=>$_P['copytype']));
	if ($info['error']==0) {
		$input = $info['system'];
	    $appid = $_G['platform'] ['key'];
    	$secret = $_G['platform'] ['secret'];
    	$input['appid'] = $appid;
    	$input['secret'] = $secret;
    	$payment = db_find("SELECT payment FROM ".tablename('uni_settings')." WHERE uniacid= '{$_G['mpid']}'");
    	$payment = unserialize($payment['payment']);
    	$input['mchid'] = $payment['wechat']['mchid'];
    	$input['apikey'] = $payment['wechat']['apikey'];
    	if ($system['s']['domain1']!="www.yixuan.net" && DOMAIN0!="19.yixuan.net") {
            $input['apiclient_cert'] = $system['s']['yixuancert'];
            $input['apiclient_key'] = $system['s']['yixuankey'];
	    }
    	$input['gongzhong'] = $system['gongzhong'];
    	$input['domainhead1'] = $system['domainhead1'];
    	$input['domainpingbi1'] = $system['domainpingbi1'];
    	$input['domainhead2'] = $system['domainhead2'];
    	$input['domainpingbi2'] = $system['domainpingbi2'];
    	$input['domainhead13'] = $system['domainhead3'];
    	$input['domainpingbi3'] = $system['domainpingbi3'];
    	$input['domainhead4'] = $system['domainhead4'];
    	$input['ip'] = $_SERVER['SERVER_ADDR'];
    	$input['domain'] = $_SERVER['HTTP_HOST'];
        $input['adminpass'] = 10000+rand(0,9999);
        $input['tiaozhuanurl'] = '';
	    $input['hdsending'] = 0 ;
        if ($_P['copytype']=='all') {
	        $input['hdget'] = 1 ;
	        $input['hdsourceurl'] = $info['hdsourceurl'] ;
	        $input['hdsend'] = 0 ;
	        $input['hdsendurl'] = '' ;
        }
		$this->saveSettings($input);
		echo '参数设置导入成功';

		$billlist = $info['billlist'];
		$billtongji= 0;
		if (!empty($billlist)) {
			foreach ($billlist as $index => $item) {
				unset($item['id']);
				$item['software'] = MODULE_NAME;
				$item['uniacid'] = $_G['mpid'];
		        $r = $insertid = db_insert(t_bill, $item);
		        if ($r) {
		        	$billtongji += 1;
		        }
			}
		}
		echo '提现记录' . count($billlist) .'条,实际导入' . $billtongji .'条';
	}

	Poster::softcopytable($severurl,$uniacid,$softname,'theme','');
	if ($_P['copytype']!='all') {
		$themedata= array(
			'scansum' => 0, 
			'forward' => 0, 
			'refundfee' => 0, 
			'fanscount' => 0, 
			'recordcount' => 0, 
			'ordercount' => 0, 
			'commcount' => 0, 
			'xiaoshou' => '',  
			'kefu' => '',  
			'chongzhi' => 0,  
			'jiezhang' => '',
			'softsn' => '',
		);
		db_update ( MODULE_NAME."_atheme",$themedata);
	}
	
    $sql = "SELECT * FROM " . tablename(t_theme) . " 
                    where status <> '-1' ORDER BY id desc";
    $theme = db_select($sql);
    foreach ($theme as $index => $row) {
        $settings = db_get(t_config, array('key' => $row['id']), array('value'));
        if (is_array($settings)) {
            $settings = xunserializer($settings['value']);
            $config =  $settings;
            $config['indexurl'] = "";
            $config['dapingurl'] = "";
            $config['addworkerurl'] = "";
            $record = array();
            $record['value'] = serialize($config);
            $return = db_update(t_config, $record, array('key' =>$row['id']));
        }
    }

    //若在原公众号已支付，则标记为跳转
	db_update ( MODULE_NAME."_aorder",array('tiaozhuan' =>1),array('paystate' =>1) );
	db_update ( MODULE_NAME."_acomm",array('tiaozhuan' =>1),array('status' =>1) );

	//更新公众平台编号
    $theme = db_find("SELECT * FROM " . tablename(t_theme) . " where status <> '-1' limit 1");
    if ($theme['uniacid'] !== $_G['mpid']) {
    	db_update ( MODULE_NAME."_acommshare",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_ashare",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_arelation",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_ascan",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_afans",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_aorder",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_acomm",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_acode",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_aexchange",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_afake",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_afanpaichoujiang",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_afanpaijihui",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_afriend",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_ahexiao",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_ateam",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_aworker",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_aworkerreport",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_atheme",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_aconfig",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_agift",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_agiftgroup",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_arecord",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_aposter",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_aqrlist",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_ashangjia",array('uniacid' =>$_G['mpid']) );
		db_update ( MODULE_NAME."_ashangjiagroup",array('uniacid' =>$_G['mpid']) );
    }
    
	$url = createWebUrl($do, array('op'=>'finished','soft'=>$soft,'copytype'=>$_P['copytype']));
	echo "<script language='javascript' type='text/javascript'>";
	echo "window.location.href='$url';"; 
	echo "</script>";  
}

if ($op == 'copy') {
	$softname = $_P['softname'];
	$tablename = $_P['tablename'];
	$page = intval($_P['page']);
	$total = intval($_P['total']);
	echo $softname  . "-" . $tablename . "正在导入第" . $page . "页/共" .ceil($total / 3000) . "页<br>";
	switch ($tablename) {
		case 'commshare':
			$filedname ='uid,openid';
			break;
		case 'share':
			$filedname ='uid,openid,fromuid,fopenid,workerid';
			break;
		case 'relation':
			$filedname ='uid,openid,parentid,popenid,workerid';
			break;
		case 'scan':
			$filedname ='uid,openid,fromuid,fopenid,workerid';
			break;
		case 'fans':
			$filedname ='uid,openid,fromuid,fopenid,workerid';
			break;
		case 'order':
			$filedname ='uid,openid,workerid';
			break;
		case 'comm':
			$filedname ='uid,openid,fromuid,fopenid,workerid';
			break;
		default:
			$filedname ='uid,openid,fromuid,fopenid,workerid';
			break;
	}
	Poster::softcopytable($severurl,$uniacid,$softname,$tablename,$filedname,$_P['page']);
	if ($page *3000 < intval($total )){
		$url = createWebUrl($do, array('op'=>'copy','soft'=>$soft,'softname'=>$softname,'page'=>$page+1,'tablename'=>$_P['tablename'],'total'=>$total));
		echo "<script language='javascript' type='text/javascript'>";
		echo "window.location.href='$url';"; 
		echo "</script>";  
		exit;
	}else{
		$info = Poster::softfirst($severurl ,$soft);
		$count = $info['count'];
		if ($tablename == 'commshare') {
			$tablename = 'share';
			$total = $count['share'];
		}elseif ($tablename == 'share') {
			$tablename = 'relation';
			$total = $count['relation'];
		}elseif ($tablename == 'relation') {
			$tablename = 'scan';
			$total = $count['scan'];
		}elseif ($tablename == 'scan') {
			$tablename = 'fans';
			$total = $count['fans'];
		}elseif ($tablename == 'fans') {
			$tablename = 'order';
			$total = $count['order'];
		}elseif ($tablename == 'order') {
			$tablename = 'comm';
			$total = $count['comm'];
		}elseif ($tablename == 'comm') {
			$url = createWebUrl($do, array('op'=>'copytheme','soft'=>$soft,'copytype'=>'all'));
			echo "<script language='javascript' type='text/javascript'>";
			echo "window.location.href='$url';"; 
			echo "</script>";  
		}
		$page = 0;
		$url = createWebUrl($do, array('op'=>'copy','soft'=>$soft,'softname'=>$softname,'page'=>$page+1,'tablename'=>$tablename,'total'=>$total));
		echo "<script language='javascript' type='text/javascript'>";
		echo "window.location.href='$url';"; 
		echo "</script>"; 
		

	}
}

if ($op == 'copyall') {
	// ignore_user_abort (true);
	// set_time_limit (0);
	
	$info = Poster::softfirst($severurl ,$soft);
	$list = $info['theme'];
	$count = $info['count'];
	$softname = $info['softname'];

    foreach ($list as $index => $row) {
    	if (!empty($row['softsn'])) {
			$softsndata = array(
				'software'    => MODULE_NAME,
				'softsource'    => $softname,
	            'uniacid'  => $_G['mpid'],
				'themeid' => $row['id'],
				'user' => $_G['username'],
				'softsn' => $row['softsn'],
				'endtime'=>$row['endtime'],
			);
			//http://oa.yixuan.net/app/index.php?i=2&c=entry&do=getbanklist&m=yx99999&op=copytheme&softsn=025f6ee963c584bbda0d5a9762da9b1a&software=softname&softsource=kk31164&server=30.yixuan.net&uniacid=2&
			$oainfo = Poster::Getbanklist($system,'copytheme',$softsndata);
			if ($oainfo['error']==0) {
				echo "活动".$row['id'] . "激活码变更成功：" . $oainfo['msg'] ."<br>";
			}else{
				echo "活动".$row['id'] . "激活码变更出错：" . $oainfo['msg'] ."<br>";
			}
    	}else{
    		echo $row['id']."未激活";
    	}
	}


    foreach ($list as $index => $row) {
		$softsndata = array(
			'software'    => MODULE_NAME,
			'softsource'    => $softname,
            'uniacid'  => $_G['mpid'],
			'themeid' => $row['id'],
			'user' => $_G['username'],
			'softsn' => $row['softsn'],
			'endtime'=>$row['endtime'],
		);
		//http://oa.yixuan.net/app/index.php?i=2&c=entry&do=getbanklist&m=yx99999&op=copytheme&softsn=025f6ee963c584bbda0d5a9762da9b1a&software=softname9&softsource=kk31164&server=30.yixuan.net&uniacid=2&
		$oainfo = Poster::Getbanklist($system,'copytheme2',$softsndata);
		if ($oainfo['error']==0) {
			echo "活动".$row['id'] . "提现记录变更成功：" . $oainfo['msg'] ."<br>";
		}elseif ($oainfo['error']==2) {
			echo "活动".$row['id'] . "没有提现记录<br>";
		}else{
			echo "活动".$row['id'] . "激活码变更出错：" . $oainfo['msg'] ."<br>";
		}
	}

	echo "正在导入". $softname  . "第1步<br>";

	// $info = Poster::softcopy($severurl,$list,$softname);

	//复制粉丝
	// 	Poster::softcopytable($severurl,$uniacid,$softname,'fans','uid,openid,fromuid,fopenid,workerid');
	Poster::softcopytable($severurl,$uniacid,$softname,'code','uid,openid');
	// 	Poster::softcopytable($severurl,$uniacid,$softname,'comm','uid,openid,fromuid,fopenid,workerid');
	// 	Poster::softcopytable($severurl,$uniacid,$softname,'commshare','uid,openid');
	Poster::softcopytable($severurl,$uniacid,$softname,'exchange','uid,openid,workerid');
	Poster::softcopytable($severurl,$uniacid,$softname,'fake','');
	Poster::softcopytable($severurl,$uniacid,$softname,'fanpaichoujiang','uid,openid,workerid');
	// Poster::softcopytable($severurl,$uniacid,$softname,'fanpaijihui','uid,openid,fromuid,fopenid,workerid');
	// Poster::softcopytable($severurl,$uniacid,$softname,'friend','uid,openid,fromuid,fopenid,workerid');
	// Poster::softcopytable($severurl,$uniacid,$softname,'hexiao','uid,workerid');
	// 	Poster::softcopytable($severurl,$uniacid,$softname,'order','uid,openid,workerid');
	// Poster::softcopytable($severurl,$uniacid,$softname,'record','uid,openid,fromuid,fopenid,workerid');
	// 	Poster::softcopytable($severurl,$uniacid,$softname,'relation','uid,openid,parentid,popenid,workerid');
	// 	Poster::softcopytable($severurl,$uniacid,$softname,'scan','uid,openid,fromuid,fopenid,workerid');
	// 	Poster::softcopytable($severurl,$uniacid,$softname,'share','uid,openid,fromuid,fopenid,workerid');
	// Poster::softcopytable($severurl,$uniacid,$softname,'team','');
	// Poster::softcopytable($severurl,$uniacid,$softname,'worker','uid,openid');
	// Poster::softcopytable($severurl,$uniacid,$softname,'workerreport','workerid');

		$url = createWebUrl($do, array('op'=>'copyall2','soft'=>$soft));
		echo "<script language='javascript' type='text/javascript'>";
		echo "window.location.href='$url';"; 
		echo "</script>";  
		exit;
}
if ($op == 'copyall2') {
	$info = Poster::softfirst($severurl ,$soft);
	$list = $info['theme'];
	$count = $info['count'];
	$softname = $info['softname'];
	echo "正在导入". $softname  . "第2步<br>";

	//复制粉丝
	Poster::softcopytable($severurl,$uniacid,$softname,'fanpaijihui','uid,openid,fromuid,fopenid,workerid');
	Poster::softcopytable($severurl,$uniacid,$softname,'friend','uid,openid,fromuid,fopenid,workerid');
	Poster::softcopytable($severurl,$uniacid,$softname,'hexiao','uid,workerid');
	Poster::softcopytable($severurl,$uniacid,$softname,'record','uid,openid,fromuid,fopenid,workerid');
		$url = createWebUrl($do, array('op'=>'copyall3','soft'=>$soft));
		echo "<script language='javascript' type='text/javascript'>";
		echo "window.location.href='$url';"; 
		echo "</script>";  
		exit;
}

if ($op == 'copyall3') {
	$info = Poster::softfirst($severurl ,$soft);
	$list = $info['theme'];
	$count = $info['count'];
	$softname = $info['softname'];
	echo "正在导入". $softname  . "第3步<br>";

	// $info = Poster::softcopy($severurl,$list,$softname);

	//复制粉丝

	Poster::softcopytable($severurl,$uniacid,$softname,'team','');
	Poster::softcopytable($severurl,$uniacid,$softname,'worker','uid,openid');
	Poster::softcopytable($severurl,$uniacid,$softname,'workerreport','workerid');

	$total = $count['commshare'];
	$page = 0;
	$tablename = "commshare";
	$url = createWebUrl($do, array('op'=>'copy','soft'=>$soft,'softname'=>$softname,'page'=>$page+1,'tablename'=>$tablename,'total'=>$total));
	echo "<script language='javascript' type='text/javascript'>";
	echo "window.location.href='$url';"; 
	echo "</script>"; 
	exit;
}


}
}